#include <cctype>
#include <iostream>
#include <string>
#include <vector>
#include<stack>
using namespace std;
int getmaxfor(string& code)
{
    stack<bool> iscursy;//记录当前的{}是否是for循环的{}
    int cur_deep = 0;//当前所在的for循环的深度
    int max_deep = 0;//最深的for循环深度
    bool isrightsy = false;//记录下一个的{}是否是for循环的{}
    for(int i = 0;i<code.size();)
    {
        if(i+2<code.size()&&code.substr(i,3) == "for"&&(i+2>=code.size()||!isalpha(code[i+3])))
        {
            isrightsy = true;
            i+=3;
            continue;
        }//这是一个for循环
        if(code[i] =='{')
        {
            iscursy.push(isrightsy);
            if(isrightsy)
            {
                    cur_deep++;
                    max_deep = max(max_deep,cur_deep);
                    isrightsy = false;
            }
        }
        else if(code[i] == '}')
        {
            if(!iscursy.empty())
            {
                if(iscursy.top())
                {
                    cur_deep--;
                }
               iscursy.pop();
            }
        }
        i++;
    }
    return max_deep;
}
int main() {
    string code;
    string line;
    while(getline(cin,line))
    {
        code =code+line+"\n";   
    }
    cout<<getmaxfor(code)<<endl;
    return 0;
}